#pragma once
#include "afxwin.h"
#include "AllTabs.h"
#include "Album.h"
#include "afxcmn.h"
#include "picview.h"
#include "resource.h"
#include "preftab.h"
#include "listctrlcolor.h"
#include "resizablepage.h"
#include "mini.h"

// CAlbumsTab dialog
class CAllTabs;
class CReviewsTab;
class CCoverTab;
class CID3Tab;

#define BUTTON_SEARCH "Search"
#define BUTTON_SEARCH_STOP "STOP!"


class CAlbumsTab : public CResizablePage
{
	DECLARE_DYNAMIC(CAlbumsTab)

public:
	CAlbumsTab(CAllTabs* allTabs, CCoverTab *coverTab, CReviewsTab *reviewTab, CPrefTab *prefs, CID3Tab *id3Tab);
	virtual ~CAlbumsTab();

// Dialog Data
	enum { IDD = IDD_ALBUMSTAB };

protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support

	DECLARE_MESSAGE_MAP()
public:
	CEdit _editFind;
	BOOL _searching;
	CList<Album*, Album*>	*_searchResult;
	Album					*_currentAlbum;
	CAllTabs *_allTabs;
	CReviewsTab *_reviewTab;
	CCoverTab *_coverTab;

	BOOL setSearchReady(CList<Album*, Album*> *result);
	BOOL setResult(CList<Album*, Album*> *result);

private:
	BOOL displayAlbum(void);

private:

private:
	BOOL clearAlbum(void);
private:
	BOOL displayList(void);

public:
	CEdit _artist;
	CListCtrlColor _trackList;
	CListCtrlColor _albumList;
	CEdit _date;
	CEdit _trackNum;
	CEdit _price;
	CEdit _rating;
	CPicView _pic;
	BOOL _refresh;

	afx_msg void OnBnClickedFind();
	afx_msg void OnBnClickedMore();
	virtual BOOL OnInitDialog();
//	afx_msg void OnLvnItemActivateTracksList(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg void OnLvnItemActivateAlbumsList(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg void OnLvnColumnclickTracksList(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg void OnLvnColumnclickAlbumsList(NMHDR *pNMHDR, LRESULT *pResult);

private:
	static int CALLBACK MyCompareTracks(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort);
	static int CALLBACK MyCompareTracksD(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort);
	static int CALLBACK MyCompareProc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort);
	static int CALLBACK MyCompareProcD(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort);
	static int CALLBACK MyCompareProcMatch(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort);

public:
	afx_msg void OnLvnKeydownAlbumList(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg void OnPaint();
	afx_msg void OnBnClickedBuy();
	afx_msg void OnBnClickedScanPl();
	void OnBuyNew(void);
	void OnBuyUsed(void);
	void OnDownload(void);
	void OnReload(void);
	void OnSimilar(void);

public:
	BOOL triggerDownload(CString name, BOOL reload = FALSE, BOOL connect = TRUE);
private:
	int setCurrentAlbum(Album *album);
public:
	CPrefTab *_prefs;
	CID3Tab	*_ID3Tab;
	CEdit _genre;
	afx_msg void OnTimer(UINT nIDEvent);

private:
	int matchAlbum(void);
public:
	int selectProposal(void);
	Album* _proposalAlbum;
	void OnProposal(void);
	afx_msg void OnBnClickedProposal();

private:
	int scanPlaylist(void);
public:
	void OnLyrics(void);
	void OnBio(void);
	CButton _searchButton;
	afx_msg void OnSize(UINT nType, int cx, int cy);
	CMini _miniWnd;
	virtual BOOL PreTranslateMessage(MSG* pMsg);
	void OnLyrics1(void);
	void OnLyrics2(void);
	void OnBio1(void);
	int googleQuery(CString googleBase, CString keys);
	afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
	void OnScan(void);
	afx_msg void copyToClipboard();
//	afx_msg void OnNMClickTracks(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg void OnNMDblclkTracks(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg void OnNMRclickList1(NMHDR *pNMHDR, LRESULT *pResult);
};
